//
//  BoxAddAlertFooterAddView.m
//  XLDoctor
//
//  Created by longma on 2018/10/10.
//  Copyright © 2018年 XLH. All rights reserved.
//

#import "ArchivesSectionView.h"
#import "UICollectionViewLeftAlignedLayout.h"
#import "ZTagClvCell.h"
@interface ArchivesSectionView ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) NSMutableArray *radioArray;
@property (nonatomic, strong) NSMutableArray *letterArray;
@property (assign, nonatomic) BOOL isShowAll;

@end
@implementation ArchivesSectionView

- (void)awakeFromNib{
    [super awakeFromNib];
 
    [self setCollectionViewUI:self.radioCollectionView];
   
    self.letterArray = [NSMutableArray array];
    MJCommonModel *model = [[MJCommonModel alloc]init];
    model.title = MJUILocalizedString(@"All");
    model.isSelect = true;
    [self.letterArray addObject:model];
    for (int i = 0; i<26; i++) {
        char character = 65 + i;
        NSString *tempString = [NSString stringWithFormat:@"%c", character];

        MJCommonModel *model = [[MJCommonModel alloc]init];
        model.title = tempString;
        
        [self.letterArray addObject:model];
    }
    //
    //一句代码 深拷贝
//    NSArray <GeneralItemModel *>*deepCopyAry = [NSMutableArray yy_modelArrayWithClass:[GeneralItemModel class] json:[self.letterArray yy_modelToJSONData]];
    
//    self.radioArray = [NSMutableArray arrayWithArray:deepCopyAry];
//    [self.radioCollectionView reloadData];


}
- (void)setFirstLetterArray:(NSMutableArray *)firstLetterArray {
    _firstLetterArray = firstLetterArray;
    
    if(firstLetterArray.count){
            self.radioArray = firstLetterArray;
            [self.radioCollectionView reloadData];
    }

}
- (void)setCollectionViewUI:(UICollectionView *)collectionView{
    UICollectionViewLeftAlignedLayout *layout = [[UICollectionViewLeftAlignedLayout alloc] init];
    
    layout.sectionInset = UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f);//每个区的空隙
    layout.minimumInteritemSpacing = 5; //列与列之间的间距
    layout.minimumLineSpacing = 6;//行与行之间的间距

    collectionView.collectionViewLayout = layout;
    collectionView.backgroundColor = UIColor.clearColor;
    collectionView.delegate = self;
    collectionView.dataSource = self;
    UINib *cell = [UINib nibWithNibName:@"ZTagClvCell" bundle:nil];
    [collectionView registerNib:cell forCellWithReuseIdentifier:@"ZTagClvCell"];
 
    
}

#pragma mark - CollectionView 代理方法
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.radioArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    ZTagClvCell *cell = (ZTagClvCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"ZTagClvCell" forIndexPath:indexPath];
    
    MJCommonModel *model = self.radioArray[indexPath.item];
    cell.model = model;
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
//    CGFloat width = (SCREEN_WIDTH -30 - (9*5))/10;
//    width *= 1000;
//    NSLog(@"width====%.f", width);  //打印的为5.24
//    NSLog(@"width1111====%.2f", floor(width)/1000);  //打印的为5.24
//    CGFloat width11 = floor(width)/1000;
//
//    if(indexPath.item == 0){
//        return CGSizeMake(width11*2 + 5,35);
//    }else{
//        return CGSizeMake(width11,35);
//    }
    
    CGFloat width = (SCREEN_WIDTH -30 - (9*5))/10;
    width *= 1000;
//    NSLog(@"width====%.f", width);  //打印的为5.24
//    NSLog(@"width1111====%.2f", floor(width)/1000);  //打印的为5.24
    CGFloat width11 = floor(width)/1000;
    
    if(indexPath.item == 0){
        return CGSizeMake(width11*2 + 4,35);
    }else{
        return CGSizeMake(width11,35);
    }

}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    for (int i = 0; i<self.radioArray.count; i++) {
        MJCommonModel *model = self.radioArray[i];
        model.isSelect = false;
    }
    MJCommonModel *model = self.radioArray[indexPath.item];
    model.isSelect = true;
    
    [self.radioCollectionView reloadData];

    //
    if(self.delegate && [self.delegate respondsToSelector:@selector(collectionViewdidSelectItemAtIndex:)])
      [self.delegate collectionViewdidSelectItemAtIndex:indexPath.item];
    
}


- (void)layoutSubviews{
    [super layoutSubviews];

    
}
@end
